package com.yj.timecapsule.common.utils;



import com.yj.timecapsule.common.enums.ErrorCode;
import com.yj.timecapsule.common.error.BusinessException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Sean
 */
public class PhoneNumberValidator {
    private static final String PHONE_REGEX = "^1[3-9]\\d{9}$";
    private static final Pattern PHONE_PATTERN = Pattern.compile(PHONE_REGEX);

    private static boolean isValidPhoneNumber(String phoneNumber) {
        Matcher matcher = PHONE_PATTERN.matcher(phoneNumber);
        return matcher.matches();
    }
    public static void valid(String phoneNumber){
        boolean b = isValidPhoneNumber(phoneNumber);
        if (!b){
            throw new BusinessException(ErrorCode.PHONE_NUMBER_ERROR);
        }
    }


}